home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1994 June / PC Plus Super CD coverdisc Issue 93 June 1994.iso / suprdisk / button / frmbutto.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1994-04-12  |  49.2 KB  |  1,302 lines

  1. VERSION 2.00
  2. Begin Form frmButton 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "Buttons"
  5.    ClientHeight    =   6630
  6.    ClientLeft      =   675
  7.    ClientTop       =   1035
  8.    ClientWidth     =   9480
  9.    ClipControls    =   0   'False
  10.    FontTransparent =   0   'False
  11.    Height          =   7320
  12.    Icon            =   FRMBUTTO.FRX:0000
  13.    Left            =   615
  14.    LinkTopic       =   "Form1"
  15.    ScaleHeight     =   442
  16.    ScaleMode       =   3  'Pixel
  17.    ScaleWidth      =   632
  18.    Top             =   405
  19.    Width           =   9600
  20.    Begin PictureBox picMaster 
  21.       AutoRedraw      =   -1  'True
  22.       AutoSize        =   -1  'True
  23.       Height          =   13980
  24.       Left            =   4350
  25.       Picture         =   FRMBUTTO.FRX:0302
  26.       ScaleHeight     =   930
  27.       ScaleMode       =   3  'Pixel
  28.       ScaleWidth      =   58
  29.       TabIndex        =   11
  30.       Top             =   945
  31.       Visible         =   0   'False
  32.       Width           =   900
  33.    End
  34.    Begin Frame Frame1 
  35.       BackColor       =   &H00C0C0C0&
  36.       ClipControls    =   0   'False
  37.       ForeColor       =   &H00C0C0C0&
  38.       Height          =   2895
  39.       Left            =   7500
  40.       TabIndex        =   15
  41.       Top             =   2205
  42.       Visible         =   0   'False
  43.       Width           =   1290
  44.       Begin CommandButton cmdFonts 
  45.          Cancel          =   -1  'True
  46.          Caption         =   "&Fonts"
  47.          Height          =   420
  48.          Left            =   150
  49.          TabIndex        =   10
  50.          Top             =   1215
  51.          Width           =   990
  52.       End
  53.       Begin TextBox tbxPrint 
  54.          Height          =   645
  55.          Left            =   150
  56.          MultiLine       =   -1  'True
  57.          TabIndex        =   8
  58.          Top             =   360
  59.          Width           =   990
  60.       End
  61.       Begin CommandButton cmdCancel 
  62.          Caption         =   "Cancel"
  63.          Height          =   420
  64.          Left            =   150
  65.          TabIndex        =   17
  66.          Top             =   1800
  67.          Width           =   990
  68.       End
  69.       Begin CommandButton cmdOK 
  70.          Caption         =   "OK"
  71.          Height          =   420
  72.          Left            =   150
  73.          TabIndex        =   16
  74.          Top             =   2340
  75.          Width           =   990
  76.       End
  77.    End
  78.    Begin PictureBox picTools 
  79.       Align           =   1  'Align Top
  80.       BackColor       =   &H00C0C0C0&
  81.       ClipControls    =   0   'False
  82.       Height          =   915
  83.       Left            =   0
  84.       ScaleHeight     =   59
  85.       ScaleMode       =   3  'Pixel
  86.       ScaleWidth      =   630
  87.       TabIndex        =   9
  88.       Top             =   0
  89.       Width           =   9480
  90.       Begin Label lblToolType 
  91.          Alignment       =   2  'Center
  92.          BackColor       =   &H00FFFFFF&
  93.          BorderStyle     =   1  'Fixed Single
  94.          Caption         =   "Pen"
  95.          Height          =   240
  96.          Left            =   7650
  97.          TabIndex        =   13
  98.          Top             =   90
  99.          Width           =   1590
  100.       End
  101.       Begin Label lblCol 
  102.          BackColor       =   &H00000000&
  103.          BorderStyle     =   1  'Fixed Single
  104.          Height          =   330
  105.          Left            =   7500
  106.          TabIndex        =   12
  107.          Top             =   45
  108.          Width           =   1890
  109.       End
  110.    End
  111.    Begin PictureBox picButton 
  112.       AutoRedraw      =   -1  'True
  113.       BackColor       =   &H00FFFFFF&
  114.       BorderStyle     =   0  'None
  115.       ClipControls    =   0   'False
  116.       ForeColor       =   &H00FFFFFF&
  117.       Height          =   510
  118.       Index           =   2
  119.       Left            =   1725
  120.       ScaleHeight     =   34
  121.       ScaleMode       =   3  'Pixel
  122.       ScaleWidth      =   41
  123.       TabIndex        =   4
  124.       Top             =   5850
  125.       Visible         =   0   'False
  126.       Width           =   615
  127.    End
  128.    Begin PictureBox picButton 
  129.       AutoRedraw      =   -1  'True
  130.       BackColor       =   &H00FFFFFF&
  131.       BorderStyle     =   0  'None
  132.       ClipControls    =   0   'False
  133.       FillColor       =   &H00808080&
  134.       ForeColor       =   &H00808080&
  135.       Height          =   510
  136.       Index           =   1
  137.       Left            =   900
  138.       ScaleHeight     =   34
  139.       ScaleMode       =   3  'Pixel
  140.       ScaleWidth      =   41
  141.       TabIndex        =   3
  142.       Top             =   5850
  143.       Visible         =   0   'False
  144.       Width           =   615
  145.    End
  146.    Begin PictureBox picButton 
  147.       AutoRedraw      =   -1  'True
  148.       BackColor       =   &H00FFFFFF&
  149.       BorderStyle     =   0  'None
  150.       ClipControls    =   0   'False
  151.       ForeColor       =   &H00000000&
  152.       Height          =   510
  153.       Index           =   0
  154.       Left            =   150
  155.       ScaleHeight     =   34
  156.       ScaleMode       =   3  'Pixel
  157.       ScaleWidth      =   41
  158.       TabIndex        =   2
  159.       Top             =   5850
  160.       Visible         =   0   'False
  161.       Width           =   615
  162.    End
  163.    Begin PictureBox picDraw 
  164.       BackColor       =   &H00FFFFFF&
  165.       BorderStyle     =   0  'None
  166.       Height          =   2445
  167.       Left            =   0
  168.       ScaleHeight     =   163
  169.       ScaleMode       =   3  'Pixel
  170.       ScaleWidth      =   176
  171.       TabIndex        =   0
  172.       Top             =   945
  173.       Visible         =   0   'False
  174.       Width           =   2640
  175.    End
  176.    Begin Label lblPrint 
  177.       BackStyle       =   0  'Transparent
  178.       Height          =   645
  179.       Left            =   5775
  180.       TabIndex        =   14
  181.       Top             =   3375
  182.       Visible         =   0   'False
  183.       Width           =   1140
  184.    End
  185.    Begin Label lblButton 
  186.       BackStyle       =   0  'Transparent
  187.       Caption         =   "Off (Use 'Update' to view)"
  188.       FontBold        =   0   'False
  189.       FontItalic      =   0   'False
  190.       FontName        =   "MS Sans Serif"
  191.       FontSize        =   8.25
  192.       FontStrikethru  =   0   'False
  193.       FontUnderline   =   0   'False
  194.       Height          =   195
  195.       Index           =   2
  196.       Left            =   1725
  197.       TabIndex        =   7
  198.       Top             =   5535
  199.       Visible         =   0   'False
  200.       Width           =   2415
  201.    End
  202.    Begin Label lblButton 
  203.       BackStyle       =   0  'Transparent
  204.       Caption         =   "Down"
  205.       FontBold        =   0   'False
  206.       FontItalic      =   0   'False
  207.       FontName        =   "MS Sans Serif"
  208.       FontSize        =   8.25
  209.       FontStrikethru  =   0   'False
  210.       FontUnderline   =   0   'False
  211.       Height          =   195
  212.       Index           =   1
  213.       Left            =   825
  214.       TabIndex        =   6
  215.       Top             =   5535
  216.       Visible         =   0   'False
  217.       Width           =   540
  218.    End
  219.    Begin Label lblButton 
  220.       BackStyle       =   0  'Transparent
  221.       Caption         =   "Up"
  222.       FontBold        =   0   'False
  223.       FontItalic      =   0   'False
  224.       FontName        =   "MS Sans Serif"
  225.       FontSize        =   8.25
  226.       FontStrikethru  =   0   'False
  227.       FontUnderline   =   0   'False
  228.       Height          =   195
  229.       Index           =   0
  230.       Left            =   150
  231.       TabIndex        =   5
  232.       Top             =   5535
  233.       Visible         =   0   'False
  234.       Width           =   315
  235.    End
  236.    Begin Label lblTest 
  237.       BackStyle       =   0  'Transparent
  238.       Caption         =   "Test"
  239.       Height          =   195
  240.       Left            =   8025
  241.       TabIndex        =   1
  242.       Top             =   1035
  243.       Visible         =   0   'False
  244.       Width           =   840
  245.    End
  246.    Begin Image imgTest 
  247.       Height          =   555
  248.       Left            =   8025
  249.       Top             =   1350
  250.       Width           =   615
  251.    End
  252.    Begin Menu mnuInvisible 
  253.       Caption         =   "Invisible"
  254.       Visible         =   0   'False
  255.       Begin Menu mnuMessage 
  256.          Caption         =   "Message"
  257.       End
  258.    End
  259.    Begin Menu mnuOptions 
  260.       Caption         =   "&Options"
  261.       Begin Menu mnuToolBar 
  262.          Caption         =   "&Toolbar"
  263.          Checked         =   -1  'True
  264.       End
  265.       Begin Menu mnuExit 
  266.          Caption         =   "E&xit"
  267.       End
  268.    End
  269.    Begin Menu mnuButton 
  270.       Caption         =   "&Buttons"
  271.       Begin Menu mnuButtons 
  272.          Caption         =   "New &Size Button"
  273.          Index           =   24
  274.          Shortcut        =   {F2}
  275.       End
  276.       Begin Menu mnuButtons 
  277.          Caption         =   "Next &Button"
  278.          Index           =   25
  279.          Shortcut        =   {F3}
  280.       End
  281.       Begin Menu mnuButtons 
  282.          Caption         =   "&UpDate the Disabled Button"
  283.          Index           =   26
  284.       End
  285.       Begin Menu mnuButtons 
  286.          Caption         =   "&Save to Bitmap or Disk"
  287.          Index           =   27
  288.          Shortcut        =   {F4}
  289.       End
  290.       Begin Menu mnuButtons 
  291.          Caption         =   "&Clear Current Button"
  292.          Index           =   28
  293.       End
  294.       Begin Menu mnuButtons 
  295.          Caption         =   "&Load a Master Bitmap"
  296.          Index           =   29
  297.       End
  298.       Begin Menu mnuButtons 
  299.          Caption         =   "&View or Edit the Master Bitmap"
  300.          Index           =   30
  301.       End
  302.       Begin Menu mnuButtons 
  303.          Caption         =   "&Add Text to the current button"
  304.          Index           =   31
  305.       End
  306.    End
  307.    Begin Menu mnuTools 
  308.       Caption         =   "&Tools"
  309.       Begin Menu mnuToolArray 
  310.          Caption         =   "Fill"
  311.          Index           =   16
  312.          Shortcut        =   {F5}
  313.       End
  314.       Begin Menu mnuToolArray 
  315.          Caption         =   "Pen"
  316.          Index           =   17
  317.          Shortcut        =   {F6}
  318.       End
  319.       Begin Menu mnuToolArray 
  320.          Caption         =   "Line"
  321.          Index           =   18
  322.          Shortcut        =   {F7}
  323.       End
  324.       Begin Menu mnuToolArray 
  325.          Caption         =   "Box"
  326.          Index           =   19
  327.          Shortcut        =   {F8}
  328.       End
  329.       Begin Menu mnuToolArray 
  330.          Caption         =   "Filled Box"
  331.          Index           =   20
  332.          Shortcut        =   {F9}
  333.       End
  334.       Begin Menu mnuToolArray 
  335.          Caption         =   "Circle"
  336.          Index           =   21
  337.       End
  338.       Begin Menu mnuToolArray 
  339.          Caption         =   "Filled Circle"
  340.          Index           =   22
  341.          Shortcut        =   {F11}
  342.       End
  343.    End
  344.    Begin Menu mnuHelp 
  345.       Caption         =   "&Help"
  346.    End
  347. Option Explicit
  348. Option Compare Text
  349. 'Gets the nearest solid color (QBColor)
  350. Declare Function GetNearestColor Lib "gdi" (ByVal hDC%, ByVal Col As Long) As Long
  351. 'Used to paint the picture
  352. Declare Sub FloodFill Lib "Gdi" (ByVal hDC%, ByVal X%, ByVal Y%, ByVal crColor As Long)
  353. Declare Sub ExtFloodFill Lib "Gdi" (ByVal hDC%, ByVal X%, ByVal Y%, ByVal crColor As Long, ByVal wFillType%)
  354. Const FLOODFILLSURFACE = 1
  355. Dim MouseDown As Integer
  356. Dim BlockAcross As Integer
  357. Dim BlockDown As Integer
  358. Dim DrawPicHeight As Integer
  359. Dim DrawPicWidth As Integer
  360. Dim Drawing As Integer
  361. Dim LineX As Integer
  362. Dim LineY As Integer
  363. Dim XPos As Integer
  364. Dim YPos As Integer
  365. Dim pMouseDown As Integer
  366. Dim XDiff As Integer
  367. Dim YDiff As Integer
  368. Dim NoEntry As Integer
  369. Dim Printing As Integer
  370. Dim ToolType As Integer
  371. Dim Painting As Integer
  372. Dim Loading As Integer
  373. Dim CurrentColor As Long
  374. Dim ButtonData() As bType
  375. Sub Change_Position ()
  376.     Dim n As Integer
  377.     'Resize the various elements and move them into position
  378.     picDraw.Move 0, picTools.Height, DrawPicWidth, DrawPicHeight
  379.     picDraw.Visible = True
  380.     For n = 0 To 2
  381.         B(n).Width = BitMap.ButtonWidth
  382.         B(n).Height = BitMap.ButtonHeight
  383.         lblButton(n).Move n * (BitMap.ButtonWidth + 4) + 3, picDraw.Top + picDraw.Height + 3
  384.         B(n).Move n * (BitMap.ButtonWidth + 4) + 3, lblButton(n).Top + lblButton(n).Height + 3
  385.         B(n).Visible = True
  386.     Next n
  387.     lblTest.Move picDraw.Width + 4, picTools.Height
  388.     imgTest.Move picDraw.Width + 4, lblTest.Top + lblTest.Height
  389. End Sub
  390. Sub Change_ToolBar ()
  391.     If picTools.Height > HEIGHT_OF_BUTTONS + 2 Then   'Show only color buttons
  392.         picTools.Height = HEIGHT_OF_BUTTONS + 2
  393.     Else
  394.         picTools.Height = (HEIGHT_OF_BUTTONS + 2) * 2 'Show all buttons
  395.     End If
  396.     mnuToolBar.Checked = Not mnuToolBar.Checked
  397. End Sub
  398. '   This function calls the Main Save routine                                           #
  399. '   It is invoked by the following events                                               #
  400. '       1. A new button is being loaded and the current button has not been saved       #
  401. '       2. A new size button is being loaded and the current button or the master       #
  402. '          bitmap has not been saved                                                    #
  403. '       3. If the Save button has been clicked or Save has been selected from the menu. #
  404. '       4. On exit if a button or bitmap has not been saved                             #
  405. '========================================================================================
  406. Function Check_For_Changes (WhichSave As Integer) As Integer
  407.     If Not Loading Then
  408.         frmMainSave.Tag = WhichSave
  409.         frmMainSave.Show 1
  410.         Check_For_Changes = frmMainSave.Tag
  411.     End If
  412. End Function
  413. '   This routine clears the drawing area without selecting a new button#
  414. '   and without saving any changes                                     #
  415. '=======================================================================
  416. Sub Clear_Button ()
  417.     B(0).Cls
  418.     If Editing Then
  419.         BitMap.Position = frmBitMap!picBitMap.ScaleHeight
  420.         Editing = False
  421.     End If
  422.     Draw_Button_Borders
  423.     BitBlt B(1).hDC, 4, 4, B(1).ScaleWidth - 7, B(1).ScaleHeight - 7, B(0).hDC, 4, 4, SRCCOPY
  424.     Re_Paint_Picture
  425.     ButtonChanged = False
  426. End Sub
  427. '   If routines are selected from the menu bar they     #
  428. '   are still called by simulating clicking the buttons #
  429. '   this insures that any 'sticky' buttons are released #
  430. '   or stuck down where appropriate                     #
  431. '========================================================
  432. Sub Click_Button (ButNum As Integer)
  433.     Tool_MouseDown ButNum
  434.     Tool_MouseUp ButNum
  435. End Sub
  436. '   This is the cancel button in the Add Text frame (frame1)
  437. Sub cmdCancel_Click ()
  438.     Printing = False
  439.     Frame1.Visible = False
  440.     lblPrint.Visible = False
  441.     HelpItem = 0
  442. End Sub
  443. Sub cmdFonts_Click ()
  444.     'Show the Fonts window
  445.     Get_Fonts
  446.     tbxPrint.SetFocus
  447. End Sub
  448. '   See mnuText_Click for explanation of the 'Add Text' routine                       #
  449. '   This routine copies the area of the form covered by the test button including       #
  450. '   any text in the label lblPrint and 'AND's it to the 'Up' button                     #
  451. '   As it is an AND operation not all colors will work. So you will have to experiment  #
  452. '========================================================================================
  453. Sub cmdOK_Click ()
  454.     BitBlt B(0).hDC, 0, 0, B(0).ScaleWidth, B(0).ScaleHeight, frmButton.hDC, imgTest.Left, imgTest.Top, SRCAND
  455.     lblPrint.Visible = False
  456.     ButtonChanged = True
  457.     UpDated = False
  458.     Frame1.Visible = False
  459.     Printing = False
  460.     B(0).Refresh
  461.     Re_Paint_Picture
  462.         
  463.     HelpItem = 0
  464. End Sub
  465. '   This draws the borders of the up, down & disabled buttons '
  466. '==============================================================
  467. Sub Draw_Button_Borders ()
  468.     Dim n As Integer
  469.     For n = 0 To 2
  470.         B(n).Cls
  471.         Draw_Button_Edges n
  472.     Next n
  473. 'Up Button
  474.     Raised_Button B(0)
  475. 'Down Button
  476.     B(1).Line (1, 1)-(BitMap.ButtonWidth - 1, 1), &H808080  'QBColor(8)
  477.     B(1).Line (1, 2)-(BitMap.ButtonWidth - 1, 2), &H808080  'QBColor(8)
  478.     B(1).Line (1, 1)-(1, BitMap.ButtonHeight - 1), &H808080 'QBColor(8)
  479.     B(1).Line (2, 1)-(2, BitMap.ButtonHeight - 1), &H808080 'QBColor(8)
  480. 'Off Button
  481.     Raised_Button B(2)
  482. End Sub
  483. '   This draws the edges of the up, down & disabled buttons '
  484. '============================================================
  485. Sub Draw_Button_Edges (Num As Integer)
  486.         
  487.         B(Num).Line (1, 0)-(BitMap.ButtonWidth - 1, 0), 0
  488.         B(Num).Line (1, BitMap.ButtonHeight - 1)-(BitMap.ButtonWidth - 1, BitMap.ButtonHeight - 1), 0
  489.         
  490.         B(Num).Line (0, 1)-(0, BitMap.ButtonHeight - 1), 0
  491.         B(Num).Line (BitMap.ButtonWidth - 1, 1)-(BitMap.ButtonWidth - 1, BitMap.ButtonHeight - 1), 0
  492.         B(Num).PSet (0, 0), &HFFFFFF
  493.         B(Num).PSet (0, BitMap.ButtonHeight - 1), &HFFFFFF
  494.         B(Num).PSet (BitMap.ButtonWidth - 1, 0), &HFFFFFF
  495.         B(Num).PSet (BitMap.ButtonWidth - 1, BitMap.ButtonHeight - 1), &HFFFFFF
  496. End Sub
  497. Sub Draw_Grid ()
  498.     Dim n As Integer
  499.     For n = 24 To DrawPicWidth - 24 Step 8
  500.         picDraw.Line (n, 24)-(n, DrawPicHeight - 24), &H808080  'QBColor(8)
  501.     Next n
  502.     For n = 24 To DrawPicHeight - 24 Step 8
  503.         picDraw.Line (24, n)-(DrawPicWidth - 24, n), &H808080   'QBColor(8)
  504.     Next n
  505. End Sub
  506. '   PEN TOOL                                                            #
  507. '   This is the only routine that draws onto the drawing area.          #
  508. '   As it draws the corresponding points are plotted onto the           #
  509. '   Up & Down buttons.                                                  #
  510. '   All the other tools draw onto the Up button and the Up button       #
  511. '   is copied to the down button and stretched onto the drawing area    #
  512. '========================================================================
  513. Sub Draw_Point ()
  514.     Dim n As Integer
  515.     If NoEntry Then Exit Sub  ' Don't re-enter this routine while in DoEvents ***
  516.     NoEntry = True
  517.     Do While MouseDown
  518.         If Inside_Array(BlockAcross, BlockDown) Then
  519.             If GetNearestColor(B(0).hDC, B(0).Point(BlockAcross, BlockDown)) <> CurrentColor Then
  520.                 If Not ButtonChanged Then ButtonChanged = True
  521.                 picDraw.Line (BlockAcross * 8 + 1, BlockDown * 8 + 1)-(BlockAcross * 8 + 7, BlockDown * 8 + 7), CurrentColor, BF
  522.                 For n = 0 To 1
  523.                     B(n).PSet (BlockAcross + n, BlockDown + n), CurrentColor
  524.                 Next n
  525.             End If
  526.         End If
  527.         DoEvents  '***  Check if the button has been released
  528.     Loop
  529.     NoEntry = False
  530.     UpDated = False
  531.     imgTest = B(0).Image
  532. End Sub
  533. '   BOX, BOXFILL, CIRCLE, CIRCLEFILL and LINE Tools     #
  534. '   The first 'SELECT CASE' ensures that the outline    #
  535. '   of the shape you are drawing remains static if      #
  536. '   you move the cursor outside the drawing area.       #
  537. '   All the tools in this routine draw to the Up button      #
  538. '   which is copied to the other buttons by Re_Paint_Picture #
  539. '=============================================================
  540. Sub Draw_Tool ()
  541.     Dim SaveX As Integer
  542.     Dim SaveY As Integer
  543.     Dim CentreX As Single
  544.     Dim CentreY As Single
  545.     Dim Aspect As Single
  546.     Dim Radius As Single
  547.     If NoEntry Then Exit Sub
  548.     NoEntry = True
  549.     picDraw.FillStyle = 1
  550.     picDraw.DrawMode = 10
  551.     picDraw.DrawWidth = 4
  552.     Do While MouseDown
  553.         Select Case BlockAcross
  554.             Case Is < Box.rLeft
  555.                 SaveX = (Box.rLeft * 8) + 4
  556.             Case Box.rLeft To Box.rRight
  557.                 SaveX = (BlockAcross * 8) + 4
  558.             Case Else
  559.                 SaveX = (Box.rRight * 8) + 4
  560.         End Select
  561.         Select Case BlockDown
  562.             Case Is < Box.rTop
  563.                 SaveY = (Box.rTop * 8) + 4
  564.             Case Box.rTop To Box.rBottom
  565.                 SaveY = (BlockDown * 8) + 4
  566.             Case Else
  567.                 SaveY = (Box.rBottom * 8) + 4
  568.         End Select
  569.         Select Case ToolType
  570.             Case T_LINE
  571.                 picDraw.Line (LineX, LineY)-(SaveX, SaveY)
  572.                 picDraw.Line (LineX, LineY)-(SaveX, SaveY)
  573.             Case Else 'T_BOX, T_BOX_FILL, T_CIRCLE, T_CIRCLEFILL
  574.                 picDraw.Line (LineX, LineY)-(SaveX, SaveY), , B
  575.                 picDraw.Line (LineX, LineY)-(SaveX, SaveY), , B
  576.         End Select
  577.         DoEvents 'Check if the button has been released
  578.     Loop
  579.     NoEntry = False
  580.     On Error Resume Next
  581.     picDraw.DrawMode = 13
  582.     picDraw.DrawWidth = 1
  583.     Select Case ToolType
  584.         Case T_LINE
  585.             B(0).Line ((LineX - 4) \ 8, (LineY - 4) \ 8)-(SaveX \ 8, SaveY \ 8), CurrentColor
  586.             B(0).PSet (SaveX \ 8, SaveY \ 8), CurrentColor
  587.         Case T_BOX
  588.             B(0).Line ((LineX - 4) \ 8, (LineY - 4) \ 8)-(SaveX \ 8, SaveY \ 8), CurrentColor, B
  589.         Case T_BOXFILL
  590.             B(0).FillStyle = 0
  591.             B(0).FillColor = CurrentColor
  592.             B(0).Line ((LineX - 4) \ 8, (LineY - 4) \ 8)-(SaveX \ 8, SaveY \ 8), CurrentColor, B
  593.         Case T_CIRCLEFILL, T_CIRCLE
  594.             If ToolType = T_CIRCLEFILL Then
  595.                 B(0).FillStyle = 0
  596.                 B(0).FillColor = CurrentColor
  597.             End If
  598.             If LineX > SaveX Then Swap LineX, SaveX 'assign the lowest values to LineX & LineY
  599.             If LineY > SaveY Then Swap LineY, SaveY 'this makes it easier to do the calculations
  600.             CentreX = LineX + (SaveX - LineX) \ 2
  601.             CentreY = LineY + (SaveY - LineY) \ 2
  602.             Radius = CentreX - LineX
  603.             Aspect = CentreY - LineY
  604.             Select Case Radius
  605.                 Case Is >= Aspect
  606.                         B(0).Circle (CentreX \ 8, CentreY \ 8), Radius \ 8, CurrentColor, , , (Aspect \ 8) / (Radius \ 8)
  607.                 Case Else
  608.                         B(0).Circle (CentreX \ 8, CentreY \ 8), Aspect \ 8, CurrentColor, , , (Aspect \ 8) / (Radius \ 8)
  609.             End Select
  610.         Case Else
  611.             Rem
  612.     End Select
  613.         
  614.     Re_Paint_Picture
  615.     ButtonChanged = True
  616.     B(0).FillStyle = 1
  617. End Sub
  618. '   The Up button is painted then copied to the other buttons by Re_Paint_Picture
  619. Sub Flood ()
  620.     B(0).FillStyle = 0
  621.     B(0).FillColor = CurrentColor
  622.     'ExtFloodFill doesn't seem to work in 16 color, 800 X 600 video mode
  623.     'In this programme when AutoRedraw is true.
  624.     'So turn it off
  625.     B(0).AutoRedraw = False
  626.     ExtFloodFill B(0).hDC, BlockAcross, BlockDown, B(0).Point(BlockAcross, BlockDown), FLOODFILLSURFACE
  627.     'Turn it back on
  628.     B(0).AutoRedraw = True
  629.     'Then copy the picture into the Device Context
  630.     BitBlt B(0).hDC, 0, 0, BitMap.ButtonWidth, BitMap.ButtonHeight, frmButton.hDC, B(0).Left, B(0).Top, SRCCOPY
  631.     ButtonChanged = True
  632.     UpDated = False 'The disabled button has changed
  633.     Raised_Button B(0)      'The paint is allowed to leak onto the
  634.     Draw_Button_Edges 0     'borders of the button, so redraw them
  635.     Re_Paint_Picture
  636.     B(0).FillStyle = 1
  637. End Sub
  638. Sub Form_Activate ()
  639.     HelpItem = 0
  640. End Sub
  641. Sub Form_KeyDown (KeyCode As Integer, Shift As Integer)
  642.     Dim SaveCode As Integer
  643.     SaveCode = 0
  644.     If Not Shift Then
  645.         Select Case KeyCode
  646.             Case &H70
  647.                 Cheap_Help Format$(HelpItem)
  648.             Case &H79   'You can't assign F10 as a shortcut key
  649.                         'in MENU DESIGN window so it's handled in code
  650.                 Click_Button BUTTON_CIRCLE
  651.             Case Else
  652.                 SaveCode = KeyCode
  653.         End Select
  654.         KeyCode = SaveCode
  655.     End If
  656. End Sub
  657. Sub Form_Load ()
  658.     Dim n As Integer
  659.     On Error GoTo EndErr
  660.     If GetSystemMetrics(SM_MOUSEPRESENT) = False Then
  661.         MsgBox "This programme requires a mouse", 16, "No Mouse Detected"
  662.         End
  663.     End If
  664.     ChDir app.Path
  665.     Position_Form frmButton    'Global routine to centre forms on the screen
  666.     For n = 0 To 2
  667.         picButton(n).BackColor = QBColor(7)
  668.         Set B(n) = frmButton!picButton(n)   'Make picturebox variables this saves having to type in the full form and control every time
  669.     Next n
  670.     ToolBar_Ini
  671.     keypreview = True
  672.     windowstate = 2
  673.     CR = Chr$(13) & Chr$(10)               'Carriage return + line feed for Message Boxes
  674.     picDraw.BackColor = QBColor(7)
  675.     picDraw.Move 0, 0
  676.     Loading = True                         'Flag to show that no buttons have been initialized yet
  677.     frmButton.Show
  678.     'Remove these two lines to get rid of the annoying messages
  679.     Cheap_Help "25"
  680.     Cheap_Help Format$(HelpItem)
  681. Exit Sub
  682. EndErr:
  683.     MsgBox Error$, 0, "Error No." & Str$(Err)   'Trap any unexpected errors
  684.     End
  685.     Resume
  686. End Sub
  687. Sub Form_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)
  688.     HelpItem = 0
  689. End Sub
  690. Sub Form_MouseUp (Button As Integer, Shift As Integer, X As Single, Y As Single)
  691.     'Switches from any tool to the pen if the right mouse button is pressed
  692.     If Button And 2 Then Switch_To_Pen
  693. End Sub
  694. Sub Form_QueryUnload (CANCEL As Integer, UnloadMode As Integer)
  695.     Dim z As Integer
  696.     'Check that nothing needs saving
  697.     If ButtonChanged Then z = S_INDIVIDUAL_FILE Or S_TO_BITMAP_AND_FILE
  698.     If BitMap.Changed Then z = z Or S_BITMAP
  699.     If z > 0 Then CANCEL = (Check_For_Changes(z) = CANCEL_SAVE)
  700.     'Remove this line to get rid of the annoying message
  701.     Cheap_Help "25"
  702. End Sub
  703. Sub Form_Unload (CANCEL As Integer)
  704.     End
  705. End Sub
  706. '   The Toolbar doesn't exist as seperate buttons so calculate #
  707. '   which button has been clicked from the X & Y positions on  #
  708. '   ToolBar picture.                                           #
  709. '===============================================================
  710. Function Get_ButNum (X As Integer, Y As Integer) As Integer
  711.     Dim ButtonNum As Integer
  712.     ButtonNum = X \ WIDTH_OF_BUTTONS   'The toolbar is in two rows
  713.                                        'So calculate the position along the bar
  714.     If ButtonNum > TOTAL_BUTTONS \ 2 - 1 Then
  715.         Get_ButNum = True
  716.         Exit Function                  'The cursor is beyond the last of the buttons
  717.     End If
  718.     If Y \ HEIGHT_OF_BUTTONS > 0 Then ButtonNum = 16 + ButtonNum
  719.                                        'If its the 2nd row, adjust the number
  720.     Get_ButNum = ButtonNum
  721. End Function
  722. '   Used to write text on the Drawing area #
  723. '==========================================#
  724. 'THIS FUNCTION HAS BEEN DISABLED TO MAKE THE
  725. 'PROGRAMME COMPATABLE WITH VISUAL BASIC ver 2
  726. Sub Get_Fonts ()
  727.     Cheap_Help "26"   'Fonts not available message
  728. Rem Remove the line above 'Cheap_Help "26",
  729. Rem add a common dialogue control to this form and
  730. Rem remove all the apostrophes from this point down
  731. Rem to enable this section if you have VB ver 3.0
  732.     'On Error GoTo DilErr
  733.     'CMDialog1.CancelError=true
  734.     'CMDialog1.FontName = lblPrint.FontName
  735.     'CMDialog1.FontSize = lblPrint.FontSize
  736.     'CMDialog1.FontBold = lblPrint.FontBold
  737.     'CMDialog1.FontItalic = lblPrint.FontItalic
  738.     'CMDialog1.FontUnderline = lblPrint.FontUnderline
  739.     'CMDialog1.FontStrikethru = lblPrint.FontStrikethru
  740.     'CMDialog1.Color = lblPrint.ForeColor
  741.     '
  742.     '
  743.     'CMDialog1.Flags = &H3& Or &H100&
  744.     '
  745.     'CMDialog1.Action = 4
  746.     'lblPrint.FontName = CMDialog1.FontName
  747.     'lblPrint.FontSize = CMDialog1.FontSize
  748.     'lblPrint.FontBold = CMDialog1.FontBold
  749.     'lblPrint.FontItalic = CMDialog1.FontItalic
  750.     'lblPrint.FontUnderline = CMDialog1.FontUnderline
  751.     'lblPrint.FontStrikethru = CMDialog1.FontStrikethru
  752.     'lblPrint.ForeColor = CMDialog1.Color
  753.     '
  754. 'Exit Sub
  755. 'DilErr:
  756. '    Exit Sub
  757. '     resume next
  758. End Sub
  759. '   Hide the 'Add Text frame if another button is clicked #
  760. '===========================================================
  761. Sub Hide_Frame ()
  762.     If Frame1.Visible Then
  763.         Frame1.Visible = False
  764.         Printing = False
  765.     End If
  766. End Sub
  767. Sub imgTest_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)
  768.     'Copy the 'Down' button onto the test button
  769.     If Not Printing Then imgTest = B(1).Image
  770.     HelpItem = 21
  771. End Sub
  772. Sub imgTest_MouseUp (Button As Integer, Shift As Integer, X As Single, Y As Single)
  773.     'Copy the 'Up' button onto the test button
  774.     If Not Printing Then imgTest = B(0).Image
  775. End Sub
  776. '   Start a new button
  777. Sub Initialize_Button ()
  778.     Drawing = True  'Disable the picDraw_Paint event
  779.     Switch_To_Pen               'Start with the pen
  780.     Click_Button BUTTON_BLACK   'and color black
  781.     Draw_Button_Borders
  782.                                 'Draw the buttons and stretch the 'Up' button into the drawing area
  783.     StretchBlt picDraw.hDC, 0, 0, picDraw.ScaleWidth, picDraw.ScaleHeight, B(0).hDC, 0, 0, B(0).ScaleWidth, B(0).ScaleHeight, SRCCOPY
  784.     Draw_Grid                   'Draw the grid on the drawing area
  785.     imgTest = B(0).Image        'Reset the test button
  786.     Drawing = False
  787.     ButtonChanged = False
  788.     If Editing Then
  789.         BitMap.Position = frmBitMap!picBitMap.ScaleHeight
  790.         Editing = False
  791.     End If
  792.     screen.MousePointer = 0
  793. End Sub
  794. '   This is the label used to Add Text to the button
  795. '   See mnuText for an explanation
  796. Sub lblPrint_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)
  797.     pMouseDown = True
  798.     XPos = X
  799.     YPos = Y
  800. End Sub
  801. Sub lblPrint_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
  802.     'Move the label
  803.     If pMouseDown Then
  804.         XDiff = X - XPos
  805.         YDiff = Y - YPos
  806.         lblPrint.Left = lblPrint.Left + ((XDiff) \ screen.TwipsPerPixelX)
  807.         lblPrint.Top = lblPrint.Top + ((YDiff) \ screen.TwipsPerPixelY)
  808.     End If
  809. End Sub
  810. Sub lblPrint_MouseUp (Button As Integer, Shift As Integer, X As Single, Y As Single)
  811.     pMouseDown = False
  812. End Sub
  813. Sub lblToolType_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)
  814.     mnuMessage.Caption = "Current selected tool && color"
  815.     PopupMenu mnuInvisible, 2, lblToolType.Left, lblToolType.Top + 25
  816. End Sub
  817. '   Loads a multi-button bitmap for editing
  818. Sub Load_BitMap ()
  819.     Dim z As Integer
  820.     Dim n As Integer
  821.     Dim FileName As String
  822.     On Error GoTo LoadErr
  823.     'Check if the current button or master bitmap needs saving
  824.     If ButtonChanged Then z = S_INDIVIDUAL_FILE Or S_TO_BITMAP_AND_FILE
  825.     If BitMap.Changed Then z = z Or S_BITMAP
  826.     If z > 0 Then n = Check_For_Changes(z)
  827.     If n = CANCEL_SAVE Then Exit Sub
  828.     'Get the data file for the bitmap
  829.     Do
  830.         Directory.Show 1
  831.         FileName = Directory!text1
  832.         If FileName = "" Then Exit Sub
  833.         If InStr(FileName, "_B.DAT") = 0 Then MsgBox "That is not a bitmap created by this programme" & CR & "The filename should end with _B.BMP", 48
  834.     Loop Until FileName = "" Or InStr(FileName, "_B.DAT") > 0
  835.     If Len(FileName) > 0 Then CurrentDirectory = Directory!Dir1.Path   'Save the working directory
  836.     Unload Directory
  837.     If Load_BitMap_Info(FileName) Then Exit Sub 'Read the data file and check if the bitmap exists
  838.     'Re-Size the buttons to fit the bitmap
  839.     Resize_Box
  840.     If Loading Then
  841.         Show_Controls
  842.         Loading = False
  843.     End If
  844.     'Let the picture fit the bitmap
  845.     frmBitMap!picBitMap.AutoSize = True
  846.     frmBitMap!picBitMap.Picture = LoadPicture(FileName)
  847.     frmBitMap!picBitMap.AutoSize = False
  848.     BitMapLoaded = True
  849. Exit Sub
  850. LoadErr:
  851.     MsgBox Error$
  852.     Exit Sub
  853.     Resume Next
  854. End Sub
  855. '   This function reads the data file created when the master bitmap was saved  #
  856. '   and checks that the BMP file exists                                         #
  857. '================================================================================
  858. Function Load_BitMap_Info (FileName As String) As Integer
  859.     Dim handle As Integer
  860.     Dim BitMapFile As String
  861.     Dim Msg As String
  862.     Dim SaveBitMap As BMP
  863.     On Error GoTo GetErr
  864.     SaveBitMap = BitMap     'Save the previous button information in case anything goes wrong
  865.     BitMapFile = FileName   'The filename ends in _B.DAT. We need to check that ******_B.BMP exists
  866.                             'So copy FileName into BitMapFile
  867.                             'then :-
  868.                             ' Alter BitMapFile to a BMP file
  869.     BitMapFile = Left$(BitMapFile, InStr(BitMapFile, "_B.DAT") - 1) & "_B.BMP"
  870.     If FileLen(BitMapFile) < Len(BitMap) Then Error 32700  'FileLen will force an error if the file doesn't exist
  871.                                                            'If the file is too short then generate an error
  872.     handle = FreeFile
  873.     Open FileName For Random As #handle Len = Len(BitMap) 'Open the ******_B.DAT data file
  874.         Get #handle, , BitMap
  875.     Close #handle
  876.     If BitMap.ID <> BUTTON_ID Then Error 32700            'If the first 2 bytes don't equal the
  877.                                                           'button ID then this file wasn't created by this programme
  878.                                                           'So force an error
  879.     FileName = BitMapFile    'Change the FileName to the BMP file
  880. GetOut:
  881. Exit Function
  882. GetErr:
  883.     Msg = "Unable to load a file, (See above). "
  884.     Select Case Err
  885.     Case 53         'Data file or BMP file not found
  886.         Msg = Msg & UCase$(Error$) & CR & CR & "The DATA file and the BMP file must be in the same " & CR & "directory"
  887.     Case 32700      'User defined error
  888.         Msg = Msg & "Wrong format" & CR & CR & "That is not a valid BUTTONS data file"
  889.     Case Else
  890.         Msg = Msg & Error$
  891.     End Select
  892.     MsgBox Msg, 48, BitMapFile
  893.     Load_BitMap_Info = True 'Indicates to the calling procedure that there was an error
  894.     BitMap = SaveBitMap
  895.     Resume GetOut
  896. End Function
  897. Sub Load_Individual ()
  898.     Cheap_Help "27"
  899. End Sub
  900. Sub mnuButtons_Click (Index As Integer)
  901.     Select Case Index
  902.         Case BUTTON_RESIZE
  903.             New_Size_Button
  904.         Case BUTTON_NEXT
  905.             Next_Button
  906.         Case BUTTON_UPDATE To BUTTON_PRINT
  907.             Click_Button Index
  908.         Case Else
  909.             Rem
  910.     End Select
  911. End Sub
  912. Sub mnuExit_Click ()
  913.     Unload frmButton
  914. End Sub
  915. Sub mnuHelp_Click ()
  916.     Cheap_Help Format$(HelpItem)
  917. End Sub
  918. Sub mnuToolArray_Click (Index As Integer)
  919.     Click_Button Index
  920. End Sub
  921. '   The toolbar can be reduced to show only the color buttons
  922. Sub mnuToolBar_Click ()
  923.     Change_ToolBar
  924.     Change_Position
  925. End Sub
  926. Sub New_Size_Button ()
  927.     Dim z As Integer
  928.     Dim n As Integer
  929.     Hide_Frame   'Hide the Add Text frame if it is visible
  930.     'Check for changes and exit if Cancel is selected
  931.     If ButtonChanged Then z = S_INDIVIDUAL_FILE Or S_TO_BITMAP_AND_FILE
  932.     If BitMap.Changed Then z = z Or S_BITMAP
  933.     If z > 0 Then n = Check_For_Changes(z)
  934.     If n = CANCEL_SAVE Then Exit Sub
  935.     'Get the dimensions of the new button
  936.     frmNew.Show 1
  937.     If Len(frmNew.Tag) > 0 Then
  938.         BitMap.Buttons = 0      'It's a new button so we don't need the master bitmap
  939.         Unload frmBitMap
  940.         BitMapLoaded = False
  941.         Resize_Box
  942.         If Loading Then         'Make the various elements visible if this is the first
  943.             Show_Controls       'button after the programme has loaded
  944.             Loading = False
  945.         End If
  946.     End If
  947. End Sub
  948. Sub Next_Button ()
  949.     Dim z As Integer
  950.     Dim n As Integer
  951.     'If it is the first button since loading then ask for the size
  952.     If Loading Then
  953.         Click_Button BUTTON_RESIZE
  954.         Exit Sub
  955.     End If
  956.     Hide_Frame    'Hide the 'Add Text' controls
  957.     'Save Changes
  958.     If ButtonChanged Then z = S_INDIVIDUAL_FILE Or S_TO_BITMAP
  959.     If z > 0 Then n = Check_For_Changes(z)
  960.     If n = CANCEL_SAVE Then Exit Sub
  961.     Initialize_Button
  962. End Sub
  963. '   Draws the buttons onto the ToolBar using BitBlt API
  964. '   The picture holding the tools is 32 buttons deep and
  965. '   2 buttons wide (Up and Down buttons)
  966. '   So button #1 is the first row in the picture, button 2 is
  967. '   the second and so on.
  968. '   The Up button is at position 0 across and the Down
  969. '   button is at position 0 +1 + the width of the buttons
  970. '=======================================================
  971. Sub Paint_Button (ToolNo As Integer, ButtonState As Integer)
  972.     Dim ButtonAcross As Integer
  973.     Dim ButtonDown As Integer
  974.     Dim PicLeft As Integer
  975.     If ToolNo <= 15 Then
  976.         ButtonAcross = ToolNo
  977.         ButtonDown = 0
  978.     Else
  979.         ButtonAcross = ToolNo - 16
  980.         ButtonDown = 1
  981.     End If
  982.     ButtonAcross = WIDTH_OF_BUTTONS * ButtonAcross
  983.     ButtonDown = HEIGHT_OF_BUTTONS * ButtonDown
  984.     If Not ButtonState Then
  985.         PicLeft = 0
  986.     Else
  987.         PicLeft = WIDTH_OF_BUTTONS + 1
  988.     End If
  989.     BitBlt picTools.hDC, ButtonAcross, ButtonDown, WIDTH_OF_BUTTONS, HEIGHT_OF_BUTTONS, picMaster.hDC, PicLeft, HEIGHT_OF_BUTTONS * ToolNo, SRCCOPY
  990. End Sub
  991. Sub picButton_MouseDown (Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  992.     If Button And 2 Then
  993.         HelpItem = Index + 17
  994.     End If
  995. End Sub
  996. Sub picDraw_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)
  997.     Dim n As Integer
  998.     Dim SaveColor As Long
  999.     MouseDown = True
  1000.     'If the right button is pressed and the tool isn't Pen then change to the pen
  1001.     If (Button And 2) Then
  1002.         HelpItem = 20
  1003.         If ToolType <> T_PEN Then
  1004.             Switch_To_Pen
  1005.             Exit Sub
  1006.         End If
  1007.     End If
  1008.     'Exit if centre button is pressed
  1009.     If Button And 4 Then Exit Sub
  1010.     BlockAcross = X \ 8
  1011.     BlockDown = Y \ 8
  1012.     Select Case ToolType
  1013.         Case T_PEN
  1014.             SaveColor = CurrentColor
  1015.             If Button And 2 Then           'The right button is the button background color (light grey)
  1016.                 CurrentColor = &HC0C0C0    'QBColor(7)
  1017.             End If
  1018.             Draw_Point
  1019.             CurrentColor = SaveColor
  1020.         Case T_LINE, T_BOX, T_BOXFILL, T_CIRCLE, T_CIRCLEFILL
  1021.             If Inside_Array(BlockAcross, BlockDown) Then  'Check it's inside the drawing area
  1022.                 LineX = BlockAcross * 8 + 4
  1023.                 LineY = BlockDown * 8 + 4
  1024.                 Draw_Tool
  1025.             End If
  1026.         Case T_FILL
  1027.             Flood
  1028.         Case Else
  1029.             Rem
  1030.     End Select
  1031. End Sub
  1032. Sub picDraw_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
  1033.     If Button Then
  1034.         'Curs.Across = X
  1035.         'Curs.Down = Y
  1036.         BlockAcross = X \ 8
  1037.         BlockDown = Y \ 8
  1038.     End If
  1039. End Sub
  1040. Sub picDraw_MouseUp (Button As Integer, Shift As Integer, X As Single, Y As Single)
  1041.     MouseDown = False
  1042. End Sub
  1043. Sub picDraw_Paint ()
  1044.     Dim X As Integer
  1045.     Dim Y As Integer
  1046.     If Drawing Or Loading Or Printing Then Exit Sub
  1047.     Re_Paint_Picture
  1048. End Sub
  1049. Sub picMaster_Click ()
  1050.     'This is the bitmap that holds all the toolbar buttons
  1051. End Sub
  1052. '   This is the picture at the top of the form that holds the toolbar
  1053. Sub picTools_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)
  1054.     Dim TN As Integer
  1055.     MouseDown = True
  1056.     If Button And 1 Then
  1057.         TN = Get_ButNum(CInt(X), CInt(Y))
  1058.         If TN > -1 Then Tool_MouseDown TN
  1059.     ElseIf Button And 2 Then
  1060.         Show_Function X, Y
  1061.         HelpItem = X \ WIDTH_OF_BUTTONS + 1
  1062.         If HelpItem > 16 Then HelpItem = 22
  1063.     End If
  1064. End Sub
  1065. Sub picTools_MouseUp (Button As Integer, Shift As Integer, X As Single, Y As Single)
  1066.     Dim TN As Integer
  1067.     MouseDown = False
  1068.     If Button And 1 Then
  1069.         TN = Get_ButNum(CInt(X), CInt(Y))
  1070.         If TN > -1 Then Tool_MouseUp TN
  1071.     End If
  1072. End Sub
  1073. Sub picTools_Paint ()
  1074.    Show_ToolBar
  1075. End Sub
  1076. '   This draws the highlight and shadow around the edge of the buttons
  1077. Sub Raised_Button (pic As PictureBox)
  1078.     pic.Line (1, 1)-(BitMap.ButtonWidth - 2, 1), &HFFFFFF     'QBColor(15)
  1079.     pic.Line (2, 2)-(BitMap.ButtonWidth - 3, 2), &HFFFFFF
  1080.     pic.Line (1, 1)-(1, BitMap.ButtonHeight - 2), &HFFFFFF
  1081.     pic.Line (2, 2)-(2, BitMap.ButtonHeight - 3), &HFFFFFF
  1082.     pic.Line (BitMap.ButtonWidth - 2, 1)-(BitMap.ButtonWidth - 2, BitMap.ButtonHeight - 1), &H808080  'QBColor(8)
  1083.     pic.Line (BitMap.ButtonWidth - 3, 2)-(BitMap.ButtonWidth - 3, BitMap.ButtonHeight - 1), &H808080  'QBColor(8)
  1084.     pic.Line (1, BitMap.ButtonHeight - 2)-(BitMap.ButtonWidth - 1, BitMap.ButtonHeight - 2), &H808080'QBColor(8)
  1085.     pic.Line (2, BitMap.ButtonHeight - 3)-(BitMap.ButtonWidth - 1, BitMap.ButtonHeight - 3), &H808080'QBColor(8)
  1086. End Sub
  1087. '   Most of the Tools operate directly onto the 'Up' button #
  1088. '   This is then StretchBlt'ed onto the drawing area and    #
  1089. '   BitBlt'ed onto the other buttons                        #
  1090. '   To save writing tons of code to calculate the appearance#
  1091. '   of the disabled button, it is only calculated when the  #
  1092. '   button is saved or if the Update button is pressed.     #
  1093. Sub Re_Paint_Picture ()
  1094.     StretchBlt picDraw.hDC, 0, 0, picDraw.ScaleWidth, picDraw.ScaleHeight, B(0).hDC, 0, 0, B(0).ScaleWidth, B(0).ScaleHeight, SRCCOPY
  1095.     'The grid is destroyed by StretchBlt so re-draw it
  1096.     Draw_Grid
  1097.     'Copy the drawing area of the 'Up' button to the 'Down' button offset by 1 pixel across and 1 pixel down
  1098.     BitBlt B(1).hDC, 4, 4, BitMap.ButtonWidth - 6, BitMap.ButtonHeight - 6, B(0).hDC, 3, 3, SRCCOPY
  1099.     B(1).Refresh
  1100.     'Copy the 'Up' Button to the test button
  1101.     imgTest = B(0).Image
  1102.     UpDated = False
  1103. End Sub
  1104. '   Draws a new size box
  1105. Sub Resize_Box ()
  1106.     Drawing = True
  1107.     UpDated = True
  1108.     screen.MousePointer = 11
  1109.     'The Drawing area is 8 times the size of the buttons
  1110.     DrawPicWidth = BitMap.ButtonWidth * 8
  1111.     DrawPicHeight = BitMap.ButtonHeight * 8
  1112.     'Set the limits of the drawing area (We don't want to draw on the button borders)
  1113.     'This routine fills the user defined data Box, with the 4 corners of the drawing area
  1114.     'It's the same as:-
  1115.     '   Box.rLeft=3
  1116.     '   Box.rTop=3
  1117.     '   Box.rRight=BitMap.ButtonWidth - 4
  1118.     '   Box.rBottom=BitMap.ButtonHeight - 4
  1119.     SetRect Box, 3, 3, BitMap.ButtonWidth - 4, BitMap.ButtonHeight - 4
  1120.     Change_Position
  1121.     Initialize_Button
  1122. End Sub
  1123. '   When the programme first loads, all the labels are invisible
  1124. '   When the first button has been drawn we need to make them visible
  1125. Sub Show_Controls ()
  1126.     Dim n As Integer
  1127.     If lblTest.Visible Then Exit Sub
  1128.     lblTest.Visible = True
  1129.     For n = 0 To 2
  1130.         lblButton(n).Visible = True
  1131.         B(n).Visible = True
  1132.     Next n
  1133. End Sub
  1134. Sub Show_Frame ()
  1135.     If Loading Then
  1136.         MsgBox "No button to operate on"
  1137.         Exit Sub
  1138.     End If
  1139.     HelpItem = 16
  1140.     'Show the frame that holds the controls for 'Add Text'
  1141.     Printing = True
  1142.     lblPrint.Move imgTest.Left + 3, imgTest.Top + 3, imgTest.Width - 4, imgTest.Height - 4
  1143.     Frame1.Move picDraw.Width + 1, imgTest.Top + imgTest.Height + 5
  1144.     lblPrint.Visible = True
  1145.     Frame1.Visible = True
  1146.     tbxPrint = ""
  1147.     tbxPrint.SetFocus
  1148. End Sub
  1149. '   If the right mouse button is held down over one of the toolbar #
  1150. '   buttons, a brief description of the buttons function is shown  #
  1151. '   on a pop up menu                                               #
  1152. '===================================================================
  1153. Sub Show_Function (X, Y)
  1154.     Dim Msg As String
  1155.     Dim Num As Integer
  1156.     Num = Get_ButNum(CInt(X), CInt(Y))
  1157.     Select Case Num
  1158.         Case 0 To 15: Msg = "Colour = QBColor (" & Format$(Num) & ")"
  1159.         Case BUTTON_FILL To BUTTON_CIRCLEFILL: Msg = mnuToolArray(Num).Caption
  1160.         Case BUTTON_RESIZE To BUTTON_PRINT: Msg = mnuButtons(Num).Caption
  1161.         Case Else: Msg = "BUTTONS. CopyRight G.Fairchild 1994"
  1162.     End Select
  1163.     mnuMessage.Caption = Msg
  1164.     PopupMenu mnuInvisible, 2, X, Y + 20
  1165. End Sub
  1166. '   Draws the complete toolbar by calling Paint_Button
  1167. '   32 times, to draw the 32 buttons
  1168. Sub Show_ToolBar ()
  1169.     Dim n As Integer
  1170.     If Painting Then Exit Sub
  1171.     Painting = True
  1172.     For n = 0 To TOTAL_BUTTONS - 1
  1173.         Paint_Button n, ButtonData(n).Down
  1174.     Next n
  1175.     Painting = False
  1176. End Sub
  1177. '   Swaps the values of two variables so that the first one is the smallest
  1178. Sub Swap (Big As Integer, Small As Integer)
  1179.     Dim SaveVar As Integer
  1180.     SaveVar = Big
  1181.     Big = Small
  1182.     Small = SaveVar
  1183. End Sub
  1184. '   Each time a new button is loaded the Pen is selected
  1185. Sub Switch_To_Pen ()
  1186.     If ToolType <> T_PEN Then
  1187.         Click_Button BUTTON_PEN
  1188.     End If
  1189. End Sub
  1190. Sub tbxPrint_Change ()
  1191.     lblPrint = tbxPrint
  1192. End Sub
  1193. '   Called when the mouse is released over a toolbar button
  1194. '   or the button is clicked in code
  1195. Sub Tool_Click (ToolNum As Integer)
  1196.     Dim z As Integer
  1197.     'Use the normal cursor unless the Fill Tool is selected
  1198.     If picDraw.MousePointer <> 0 And Not ButtonData(BUTTON_FILL).Down Then
  1199.         picDraw.MousePointer = 0
  1200.     ElseIf ToolNum = BUTTON_FILL Then
  1201.         picDraw.MousePointer = 10
  1202.     End If
  1203.     Select Case ToolNum
  1204.         Case 0 To 15
  1205.             CurrentColor = QBColor(ToolNum)
  1206.             lblCol.BackColor = CurrentColor   'lblCol is the label in the toolbar that shows the current color
  1207.         Case BUTTON_FILL To BUTTON_CIRCLEFILL
  1208.             If InStr(mnuToolArray(ToolNum).Caption, Chr$(9)) Then
  1209.                 lblToolType = Left$(mnuToolArray(ToolNum).Caption, 6)
  1210.             Else
  1211.                 lblToolType = mnuToolArray(ToolNum).Caption
  1212.             End If
  1213.             ToolType = ToolNum - 15
  1214.         Case BUTTON_RESIZE
  1215.              New_Size_Button
  1216.         Case BUTTON_NEXT
  1217.             Next_Button
  1218.         Case BUTTON_UPDATE
  1219.             Update_Button
  1220.         Case BUTTON_SAVE
  1221.             z = Check_For_Changes(S_SHOW_ALL)
  1222.             If z <> CANCEL_SAVE Then Initialize_Button
  1223.         Case BUTTON_CLEAR
  1224.             Clear_Button
  1225.         Case BUTTON_LOAD
  1226.             frmLoad.Show 1
  1227.             z = Val(frmLoad.Tag)
  1228.             Unload frmLoad
  1229.             Select Case z
  1230.                 Case 1: Load_Individual
  1231.                 Case 2: Load_BitMap
  1232.                 Case Else: Rem
  1233.             End Select
  1234.         Case BUTTON_VIEW
  1235.             If BitMapLoaded Then
  1236.                 frmBitMap.Show 1
  1237.             Else
  1238.                 MsgBox "There's nothing to view"
  1239.             End If
  1240.         Case BUTTON_PRINT
  1241.             Show_Frame
  1242.         Case Else
  1243.             Rem
  1244.     End Select
  1245. End Sub
  1246. '   Called by a Mouse_Down event in picTools
  1247. Sub Tool_MouseDown (ToolNum As Integer)
  1248.     If ToolNum > TOTAL_BUTTONS - 1 Then Exit Sub  'It should be impossible to select a button > 31
  1249.                                                   'but just in case it happens - exit the sub
  1250.     'Put the button down if it is not already stuck down
  1251.     If ButtonData(ToolNum).Down = False Then
  1252.         ButtonData(ToolNum).Down = True
  1253.         Paint_Button ToolNum, ButtonData(ToolNum).Down
  1254.     End If
  1255.     'If it's a color button or a tool button, make it stick
  1256.     If ToolNum < 23 Then ButtonData(ToolNum).stuck = True
  1257. End Sub
  1258. '   Called by a Mouse_Up event in picTools (The Toolbar)
  1259. Sub Tool_MouseUp (ToolNum As Integer)
  1260.     If ToolNum > TOTAL_BUTTONS - 1 Then Exit Sub
  1261.     'Save the stuck buttons so that we can release them next time
  1262.     Static SaveColBut As Integer
  1263.     Static SaveToolBut As Integer
  1264.     Select Case ButtonData(ToolNum).Group
  1265.         Case NO_GROUP                 'It's not a 'Sticky' button so release it
  1266.             ButtonData(ToolNum).Down = False
  1267.             Paint_Button ToolNum, ButtonData(ToolNum).Down
  1268.         Case COLOR_GROUP              'If it's not already stuck down then stick it & release the previous button
  1269.             If ToolNum <> SaveColBut Then
  1270.                 ButtonData(SaveColBut).Down = False
  1271.                 Paint_Button SaveColBut, ButtonData(SaveColBut).Down
  1272.                 ButtonData(SaveColBut).stuck = False
  1273.                 SaveColBut = ToolNum
  1274.             End If
  1275.         Case TOOL_GROUP               'If it's not already stuck down then stick it & release the previous button
  1276.             If ToolNum <> SaveToolBut And SaveToolBut <> 0 Then
  1277.                 ButtonData(SaveToolBut).Down = False
  1278.                 Paint_Button SaveToolBut, ButtonData(SaveToolBut).Down
  1279.                 ButtonData(SaveToolBut).stuck = False
  1280.                 SaveToolBut = ToolNum
  1281.             Else
  1282.                 SaveToolBut = ToolNum
  1283.             End If
  1284.         Case Else: Rem
  1285.     End Select
  1286.     'Invoke the routine associated with the button
  1287.     Tool_Click ToolNum
  1288. End Sub
  1289. '   Initialize the ButtonData and assign the group values
  1290. Sub ToolBar_Ini ()
  1291.     Dim n As Integer
  1292.     ReDim ButtonData(0 To TOTAL_BUTTONS - 1)
  1293.     For n = 0 To 15
  1294.         ButtonData(n).Group = COLOR_GROUP
  1295.     Next n
  1296.     For n = 16 To 22
  1297.         ButtonData(n).Group = TOOL_GROUP
  1298.     Next n
  1299.     'Menu Design wont let you assign F10 to a menu item so do it in code
  1300.     mnuToolArray(BUTTON_CIRCLE).Caption = mnuToolArray(BUTTON_CIRCLE).Caption & Chr$(9) & "F10"
  1301. End Sub
  1302.